# @Time: 2025/3/9 20:44
# @Author: chenhui
import datetime
import os

import requests


def get_now_time():
    return datetime.datetime.now()


def get_now_date_time_str():
    return datetime.datetime.now().strftime("%Y%m%d%H%M%S")


def get_project_path():
    # 获取项目的绝对路径
    project_name = "trading_system_autotest"
    file_path = os.path.dirname(__file__)
    # print(file_path[:file_path.find(project_name)+len(project_name)])
    return file_path[:file_path.find(project_name) + len(project_name)]


# 生成"/"的方法
def sep(path, add_sep_before=False, add_sep_after=False):
    all_path = os.sep.join(path)
    if add_sep_before:
        all_path = os.sep + all_path
    if add_sep_after:
        all_path = all_path + os.sep
    return all_path


def get_img_path(img_name):
    """
    获取商品图片的路径
    :param img_name:
    :return:
    """
    img_dir_path = get_project_path() + os.sep + "img" + os.sep + img_name
    return img_dir_path

def get_every_wallpaper():
    """
    从bing获取每日壁纸
    Returns:

    """
    everyday_wallpaper_url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=10&mkt=zh-CN"
    try:
        res = requests.get(url=everyday_wallpaper_url)
        wallpaper_url = "https://cn.bing.com" + res.json()["images"][0]["url"][:-7]
    except Exception as e:
        print(e)
        wallpaper_url = "https://cn.bing.com/images/search?q=%E5%88%98%E4%BA%A6%E8%8F%B2%E5%A3%81%E7%BA%B8&view=detailv2&FORM=IQFRBA&id=7A6FA1D7FC3AE2924B2C4045D5FE9517F0F09FC9&selectedindex=0&&expw=1275&exph=2267&ccid=N13eT0im&ck=5A79FD272F9DEA079477098BB8CFA773&simid=608011879471867803&thid=OIP.N13eT0im_l1su1RLvDuFnAHaNK&idpp=serp&idpbck=1&ajaxhist=0&ajaxserp=0"
    return wallpaper_url



if __name__ == '__main__':
    # print(get_now_time())
    #  get_project_path()
    # sep(["config", "environment.yaml"], add_sep_before=True)
    print(get_every_wallpaper())
